package com.ffs.template.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程工具
 *
 * @author ffs80
 */
@SuppressWarnings("unused")
public class ExecutorUtil {

    private static final ExecutorUtil INSTANCE = new ExecutorUtil();

    private ExecutorService executorService;

    public static ExecutorUtil getInstance() {
        return INSTANCE;
    }

    public ExecutorService getExecutorService() {
        return executorService;
    }

    public void setExecutorService(ExecutorService executorService) {
        this.executorService = executorService;
    }

    public void execute(Runnable r) {
        if (executorService == null) {
            executorService = Executors.newSingleThreadExecutor();
        }
        executorService.execute(r);
    }

    public void shutDown() {
        if (executorService != null) {
            executorService.shutdown();
        }
    }

    public boolean isShutDown(){
        return executorService.isShutdown();
    }
}
